<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>disposable.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
  </script>

  <script src="static/js/doc.js">
  </script>

  <meta charset="utf8">
</head>

<body onload="prettyPrint()">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_disposable_disposable.js.html">disposable.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line2"></a>// you may not use this file except in compliance with the License.
<a name="line3"></a>// You may obtain a copy of the License at
<a name="line4"></a>//
<a name="line5"></a>//     http://www.apache.org/licenses/LICENSE-2.0
<a name="line6"></a>//
<a name="line7"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line8"></a>// distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
<a name="line9"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line10"></a>// See the License for the specific language governing permissions and
<a name="line11"></a>// limitations under the License.
<a name="line12"></a>
<a name="line13"></a>// Copyright 2005 Google Inc. All Rights Reserved.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Implements the disposable interface. The dispose method is used
<a name="line17"></a> * to clean up references and resources.
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>
<a name="line21"></a>goog.provide(&#39;goog.Disposable&#39;);
<a name="line22"></a>goog.provide(&#39;goog.dispose&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>/**
<a name="line26"></a> * Class that provides the basic implementation for disposable objects. If your
<a name="line27"></a> * class holds one or more references to COM objects, DOM nodes, or other
<a name="line28"></a> * disposable objects, it should extend this class or implement the disposable
<a name="line29"></a> * interface.
<a name="line30"></a> * @constructor
<a name="line31"></a> */
<a name="line32"></a>goog.Disposable = function() {};
<a name="line33"></a>
<a name="line34"></a>
<a name="line35"></a>/**
<a name="line36"></a> * Whether the object has been disposed of.
<a name="line37"></a> * @type {boolean}
<a name="line38"></a> * @private
<a name="line39"></a> */
<a name="line40"></a>goog.Disposable.prototype.disposed_ = false;
<a name="line41"></a>
<a name="line42"></a>
<a name="line43"></a>/**
<a name="line44"></a> * @return {boolean} Whether the object has been disposed of.
<a name="line45"></a> */
<a name="line46"></a>goog.Disposable.prototype.isDisposed = function() {
<a name="line47"></a>  return this.disposed_;
<a name="line48"></a>};
<a name="line49"></a>
<a name="line50"></a>
<a name="line51"></a>/**
<a name="line52"></a> * @return {boolean} Whether the object has been disposed of.
<a name="line53"></a> * @deprecated Use {@link #isDisposed} instead.
<a name="line54"></a> */
<a name="line55"></a>goog.Disposable.prototype.getDisposed = goog.Disposable.prototype.isDisposed;
<a name="line56"></a>
<a name="line57"></a>
<a name="line58"></a>/**
<a name="line59"></a> * Disposes of the object. If the object hasn&#39;t already been disposed of, calls
<a name="line60"></a> * {@link #disposeInternal}. Classes that extend {@code goog.Disposable} should
<a name="line61"></a> * override {@link #disposeInternal} in order to delete references to COM
<a name="line62"></a> * objects, DOM nodes, and other disposable objects.
<a name="line63"></a> */
<a name="line64"></a>goog.Disposable.prototype.dispose = function() {
<a name="line65"></a>  if (!this.disposed_) {
<a name="line66"></a>    // Set disposed_ to true first, in case during the chain of disposal this
<a name="line67"></a>    // gets disposed recursively.
<a name="line68"></a>    this.disposed_ = true;
<a name="line69"></a>    this.disposeInternal();
<a name="line70"></a>  }
<a name="line71"></a>};
<a name="line72"></a>
<a name="line73"></a>
<a name="line74"></a>/**
<a name="line75"></a> * Deletes or nulls out any references to COM objects, DOM nodes, or other
<a name="line76"></a> * disposable objects. Classes that extend {@code goog.Disposable} should
<a name="line77"></a> * override this method.  For example:
<a name="line78"></a> * &lt;pre&gt;
<a name="line79"></a> *   mypackage.MyClass = function() {
<a name="line80"></a> *     goog.Disposable.call(this);
<a name="line81"></a> *     // Constructor logic specific to MyClass.
<a name="line82"></a> *     ...
<a name="line83"></a> *   };
<a name="line84"></a> *   goog.inherits(mypackage.MyClass, goog.Disposable);
<a name="line85"></a> *
<a name="line86"></a> *   mypackage.MyClass.prototype.disposeInternal = function() {
<a name="line87"></a> *     mypackage.MyClass.superClass_.disposeInternal.call(this);
<a name="line88"></a> *     // Dispose logic specific to MyClass.
<a name="line89"></a> *     ...
<a name="line90"></a> *   };
<a name="line91"></a> * &lt;/pre&gt;
<a name="line92"></a> * @protected
<a name="line93"></a> */
<a name="line94"></a>goog.Disposable.prototype.disposeInternal = function() {
<a name="line95"></a>  // No-op in the base class.
<a name="line96"></a>};
<a name="line97"></a>
<a name="line98"></a>
<a name="line99"></a>/**
<a name="line100"></a> * Calls {@code dispose} on the argument if it supports it. If obj is not an
<a name="line101"></a> *     object with a dispose() method, this is a no-op.
<a name="line102"></a> * @param {*} obj The object to dispose of.
<a name="line103"></a> */
<a name="line104"></a>goog.dispose = function(obj) {
<a name="line105"></a>  if (obj &amp;&amp; typeof obj.dispose == &#39;function&#39;) {
<a name="line106"></a>    obj.dispose();
<a name="line107"></a>  }
<a name="line108"></a>};
</pre>


</body>
</html>
